<template>
  <div class="pingjia">
    <div v-if="list.length != 0">
      <div class="item" v-for="(item,index) in list" :key="index">
        <div class="top">
          <img :src="item.goods_thumb" alt="">
          <div class="top-right">
            <p class="p1">{{item.goods_name}}</p>
            <p v-if="item.goods_attrs">套装：{{item.goods_attr}}</p>
          </div>
        </div>
        <div class="zhong">
          <p>评星级</p>
          <!-- v-model="value" -->
          <van-rate v-model="item.value" @change="chan(index)" :size="30"/>
        </div>
        <div class="foot">
          <div class="kuang">
            <!-- v-model="message" -->
            <textarea v-model="item.message"  placeholder="请输入评价内容..." maxlength="200"></textarea>
            <!-- <p>1/200字</p> -->
          </div>
          <div class="tijiaos">
            <p></p>
            <p class="tijiao" @click="tijiao(item.rec_id,index)">提交</p> 
          </div>
        </div>
      </div>
    </div>
    <div v-else>
      <p class="znawu">暂无可评论</p>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        order_id:'',
        list:[],
      }
    },
    created() {
      
    },
    mounted(){
      this.order_id = this.$route.query.order_id
      this.getlist()
    },

    methods: {
      getlist(){
        this.$get("/api/gzh_mine.php?action=order_comment_page", {
          uid:localStorage.getItem('uid'),
          order_id:this.order_id
        }).then(res => { 
          console.log(res.data,'res.data')

          
          this.list = res.data
          for(var a of this.list){
            this.list[a].value = 1
            this.list[a].contents= ''
          }
          
        }).catch(err => {

        });
      },
      chan(index){
        this.$forceUpdate()
      },
      tijiao(id,index){
        this.$axios({
            method: "post",
            url: "/api/gzh_mine.php?action=comment_order",
            data:this.$qs.stringify({
              uid:localStorage.getItem('uid'),
              order_id:this.order_id,
              rec_id:id,
              content:this.list[index].message,
              rank:this.list[index].value
            }),
            headers: {
                // 'Content-Type': 'application/x-www-form-urlencoded'
                // 'content-Type' : 'application/json'
                'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
            },
        })
        .then(response => {
            console.log(response.data)
            if(response.data.error==0){
              this.$toast(response.data.msg);
              this.getlist()

            }else{
               this.$toast(response.data.msg);
            }
           
        })
      },
    },
  }
</script>

<style scoped>
.pingjia{
  border-top: 2px solid #EFEFEF;
  width: 100%;
}
.item{
  width: 100%;
  height: 650px;
  border-bottom: 4PX solid #f7f7f7;
}
.top{
  width: 100%;
  height: 120px;
  padding: 0 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.top img{
  width: 100px;
  height: 100px;
  background: #ccc;
  margin-right: 20px;
}
.top-right{
  font-size: 28px;
  color: #333;
}
.top-right .p1{
  width: 550px;
  overflow:hidden; 
  text-overflow:ellipsis; 
  white-space:nowrap;
}



.zhong{
  width: 100%;
  height: 100px;
  padding: 0 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}
.zhong p{
  font-size: 36px;
  color: #333;
  margin-right: 30px;
}




.foot{
  width: 100%;
}
.kuang{
  width:698px;
  height:282px;
  margin: auto;
  margin-top: 30px;
  position: relative;
}
.kuang textarea{
  width:698px;
  height:282px;
  border:1PX solid rgba(204,204,204,1);
  border-radius:10px;
  margin: auto;
  padding: 20px 15px;
  box-sizing: border-box;
  font-size:26px;
  font-family:PingFang SC;
  font-weight:500;
  line-height:30px;
}
textarea{outline: none;}
.kuang p{
  position: absolute;
  right: 10px;
  bottom: 10px;
  font-size:26px;
  font-family:PingFang SC;
  font-weight:500;
  color:rgba(204,204,204,1);
  line-height:30px;
}
.tijiaos{
  width: 100%;
  height: 130px;
  padding: 0 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tijiao{
  width:120px;
  height:47px;
  
  background:rgba(6,162,85,1);
  box-shadow:0px 3px 11px 2px rgba(51,153,51,0.32);
  border-radius:50px;
  font-size:28px;
  font-family:PingFang SC;
  font-weight:bold;
  color:rgba(255,255,255,1);
  line-height:47px;
  text-align: center;
}
.znawu{
  font-size: 28px;
  color: #333;
  text-align: center;
  margin-top: 150px;
}
</style>